<template>
    <div class="login_container">
        <div class="login_box">
            <div class="avatar_box">
                <img src="../assets/logo.png"/>
            </div>
            <div class="form_box">
                <el-form ref='loginForm' :model="loginForm"  :rules="loginRules" label-width="0px">
                    <el-form-item prop="username" >
                        <el-input ref="username" name="username" type="text" placeholder="username"  v-model="loginForm.username" prefix-icon="el-icon-user-solid"></el-input>
                    </el-form-item>
                    <el-form-item prop="password">
                        <el-input ref="password" name="password"  placeholder="password" type="password" v-model="loginForm.password" prefix-icon="el-icon-lock"></el-input>
                    </el-form-item>
                    <el-form-item class="btns">
                        <el-button type="primary" @click="handleLogin" round>提交</el-button>
                        <el-button type="info" @click="handleResetLogin" round>重置</el-button>
                    </el-form-item>
                </el-form>
            </div>
        </div>
    </div>
</template>
<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'
import { ElForm } from 'element-ui/types/form'
@Component({
  name: 'login'
})
export default class extends Vue {
    private loginForm = {
      username: 'admin',
      password: '123456'
    }

    private loginRules = {
      username: [{ required: true, message: '请输入用户名.', trigger: 'blur' },
        { min: 3, max: 10, message: '字符长度在 3 到 10 之间.', trigger: 'blur' }],
      password: [{ min: 6, max: 10, message: '字符长度在 3 到 10 之间.', trigger: 'blur' }]
    }

    private handleResetLogin () {
      (this.$refs.loginForm as ElForm).resetFields()
    // this.$refs.loginFrom.resetFields()
    }

    private handleLogin () {
      (this.$refs.loginForm as ElForm).validate((valid: boolean) => {
        if (!valid) return
        this.$message.success('登录成功')
        window.sessionStorage.setItem('token', 'true')
        this.$router.push('/home')
      })
    }
}
</script>
<style lang="less" scoped>
.login_container{
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #2b4b6b;
    height: 100%;
}
.login_box{
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    width: 450px;
    height: 300px;
    background-color: #fff;
    border-radius: 10px;
    .avatar_box{
        background-color: #fff;
        width: 130px;
        height: 130px;
        border: 1px solid #eee;
        border-radius: 50%;
        padding: 10px;
        box-shadow: 0 0 10px #ddd;
        margin-top: -65px;
        img{
            width:100%;
            height: 100%;
            border-radius: 50%;
            background-color: #eee;
        }
    }
    .form_box{
        width: 100%;
        margin-top: 20px;
        margin-left: 20px;
        margin-right: 20px;
        .btns{
            display: flex;
            justify-content: flex-end;
        }
    }
}
</style>
